import time


def my_decorator(func):
    def wrapper():
        print("wrapper函数开始")
        start_time = time.perf_counter()
        func()
        end_time = time.perf_counter()
        print(f"函数运行时间：{end_time - start_time}")
        print("wrapper函数结束")
    return wrapper

@my_decorator # 装饰器：名称自定义
def for_loop():
    print("for_loop函数开始")
    for i in range(10000):
        pass
    print("for_loop函数结束")

@my_decorator
def while_loop():
    print("while_loop函数开始")
    i = 0
    while i < 10000:
        i+=1
    print("while_loop函数结束")

# new_for = my_decorator(for_loop)  # wapper
# new_for()

# 调用时，会采用装饰器调用方法。
for_loop()

# new_while = my_decorator(while_loop)
# new_while()
while_loop()



# 重分利用了函数一等公民的特性，作为入参，进行了装饰